#ifndef _TERRAIN_H
#define _TERRAIN_H

#define TILE_SIZE 533.33333f
#define TILE_COUNT 64
#define MIN_Y (-TILE_COUNT * TILE_SIZE / 2)
#define MIN_X (-TILE_COUNT * TILE_SIZE / 2)
#define MAX_Y (TILE_COUNT * TILE_SIZE / 2)
#define MAX_X (TILE_COUNT * TILE_SIZE / 2)
#define CELL_SIZE (TILE_SIZE / 8)

#define NO_COORD_RESULT		-999999.0f
#define NO_AREA_RESULT		65535

class DLL_EXPORT Landmark
{
public:
	float _x, _y, _z;
	ui32 _mapid;

	Landmark() : _x(0.0f), _y(0.0f), _z(0.0f), _mapid(0)
	{
	}
	Landmark(float x, float y, float z) : _x(x), _y(y), _z(z), _mapid(0)
	{
	}
	Landmark(float x, float y, float z, ui32 mapid) : _x(x), _y(y), _z(z), _mapid(mapid)
	{
	}
	Landmark(const Landmark& vec)
	{
		_x = vec._x;
		_y = vec._y;
		_z = vec._z;
		_mapid = vec._mapid;
	}
};

struct CellInformation
{
	ui16 AreaID[2][2];
	ui8 LiquidType[2][2];
	float LiquidLevel[2][2];
	float Z[32][32];
}; 

class DLL_EXPORT TerrainHandler
{
	friend class MapHandler;
	FILE* m_mapfile;
	ui32 CellOffset[512][512];
	ui32 map;
	CellInformation*** m_cellinfo;
	DWORD** m_lastaccess;
	CellInformation* GetCellInfo(ui32 x, ui32 y);
	void LoadCell(ui32 x, ui32 y);
	Mutex m_filemutex;
	void Update();
	bool m_cellsloaded;
public:
	TerrainHandler(ui32 mapdid);
	bool LoadMapFile();
	float GetLandHeight(float x, float y);
	ui16 GetAreaId(float x, float y);
};


#endif